<?

if(isset($this->errorMessage)){

		echo $this->errorMessage;

}?>
   <div class="middle">
    <h4><a name="Items">Members</a></h4>
     <table class="ui-widget ui-widget-content">
     <thead>
     <tr  class="ui-widget-header">
     	<td>Del</td>
        <td>Name</td>
        <td>Password</td>
        <td>Account</td>
     </tr>
     </thead>
     <?php foreach ($this->entries as $entry): ?>
     <tr>
         <?
//         href './del?user_id='.$entry->user_id;
         ?>
     	<td title='delete'><a class="del_a" href="#"
                              onclick="try{deleteUser(<?=$entry->user_id;?>,'<?=$entry->name;?>');
                              }catch (e){alert(e);}"><img src="/images/del.jpg"/>
        </a></td>
        <td><a href="./edit?user_id=<?=$entry->user_id?>"><?=$entry->name?></a></td>
        <td><?=$entry->password?></td>
        <td><?=$entry->account?></td>
     </tr>
     <?php endforeach; ?>
     </table>
     <hr/>
     <div class="link_div">
     <a href="<?=$this->url(array('controller'=>'auth','action'=>'logout'))?>">click here to logout</a>
     </div>
     </div>
<div id="dialog-confirm" title="Delete the user" style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
            <span id="dialog_content"></span></p>
</div>

<script type="text/javascript">
    function deleteUser(user_id){
//        alert(user_id+'in del');
        $("#dialog_content").text('Do you want to delete the user '+name+'?');
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
        $( "#dialog-confirm" ).dialog({
                resizable: false,
                height:200,
                modal: true,
                buttons: {
                        "Delete": function() {
//                            alert(user_id+'in del');
                                $.ajax({
                                    type:'POST',
                                    url:'/auth/del',
                                    data:{'user_id':user_id},
                                    success:function (data){
                                        alert(data);
                                        $( this ).dialog( "close" );
                                        location.reload();
                                    },
                                    dataType:'json'
                                });                               
                                $( this ).dialog( "close" );
                        },
                        Cancel: function() {
                                $( this ).dialog( "close" );
                        }
                }
        });
    }
    

</script>
            